package org.aokey.springdemo2;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
//@RestController
public class ResponseController {
    @ResponseBody
    @RequestMapping("static")
    public Object Static(){
        return "/index.html";
    }
    @RequestMapping("html")
    public Object Html(){
        return "/index.html";
    }
    @ResponseBody
    @RequestMapping("html2")
    public Object Html2(){
        return "<h1>另一个标💰</h1>";
    }
    @ResponseBody
    @RequestMapping("/JSON")
    public Object JSON(){
        Animals animals=new Animals();
        animals.setAge(5);
        animals.setName("mimi");
        animals.setColor("red");
        return animals;
    }
    @ResponseBody
    @RequestMapping("/Status")
    public Object Status(HttpServletResponse response){
        response.setStatus(200);
        return "状态码设置成功";
    }
    @ResponseBody
    @RequestMapping("/Status1")
    public Object Status1(HttpServletResponse response){
        response.setStatus(404);
        return "状态码设置成功";
    }
    @ResponseBody
    @RequestMapping(value = "/setheader",produces = "application/JSON")
    public Object setheader(){
        return "{\"name\":\"mimi\",\"age\":5,\"color\":\"red\"}";
    }
    @ResponseBody
    @RequestMapping("123456")
    public Object header(HttpServletResponse response){
        response.setHeader("name","mimi");
        return "设置成功！！！";
    }
}
